package com.atguigu.e_objectstream;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;

public class Demo {
    public static void main(String[] args) throws IOException {
        //存对象到文件中 --> 序列化操作
        ObjectOutputStream oos = new ObjectOutputStream(
                new FileOutputStream("T_Day23\\test\\obj.txt"));

//        oos.writeObject("Hello");//字符串对象
//        oos.writeObject(100);//Integer对象
//        oos.writeObject(new Date());//Date对象
//
//        //自定义对象
//        oos.writeObject(new Student("guigu001","刘德华",18,"男"));

        ArrayList<Object> list = new ArrayList<>();
        Collections.addAll(list,
                "Hello",
                100,new Date(),
                new Student("guigu001","刘德华",18,"男"));

        //把集合写到文件中
        oos.writeObject(list);

        oos.close();
    }
}
